<!--
2020-##-## 周# by chenchong
* ADD
-->
<template>
    <div class="Idminternalsystem">
        <div class="Idminternalsystem-text">司内系统</div>
        <div class="ul">
            <a-row>
                <a-col class="li" :xs="12" :sm="8" :md="8" :lg="6" :xl="4" v-for="(item,index) in dataSource" :key="index">
                        <a @click="showModal(item,index)">
                            <img :src="imgUrl + item.ICON" alt="" v-if="item.ICON !==''" >
                            <img src="../../../../public/icon.jpg" alt="" v-else>
                        </a>
                        <div class="text">
                          	<h5>{{item.SYSNAME}}</h5>
                            <p>用户账号:</p><span>{{item.USERID}}</span> <br>
                            <p>用户名:</p><span>{{item.USERNAME}}</span> <br>
                            <p>是否首次登陆:
                                <span v-if="item.FIRSTLOGIN==10">否</span>
                                <span v-else>是</span>
                            </p>
                        </div>
                </a-col>
            </a-row>
            </div>
        <!-- 对话框 -->
        <a-modal v-model="visible" title="首次登陆请输入密码:" okText="关闭" :footer = null @ok="handleOk">
            <a-form-model ref="ruleForm" :model="ruleForm" :rules="rules" v-bind="layout">
                <a-form-model-item has-feedback label="登录密码" prop="pass">
                    <a-input v-model="ruleForm.pass" type="password" autocomplete="off" />
                </a-form-model-item>
                <a-form-model-item has-feedback label="重复密码" prop="checkPass">
                    <a-input v-model="ruleForm.checkPass" type="password" autocomplete="off" />
                </a-form-model-item>
                <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }">
                    <a-button type="primary" @click="submitForm('ruleForm')">
                        确定
                    </a-button>
                    <a-button style="margin-left: 10px" @click="resetForm('ruleForm')">
                        重置
                    </a-button>
                </a-form-model-item>
            </a-form-model>
        </a-modal>
    </div>

</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { postAction } from '@/api/manage'
import JDate from '@/components/jeecg/JDate.vue'
import store from '@/store'
export default {
    name:'Idminternalsystem',
    data () {
            let checkPending
            let checkAge = (rule, value, callback) => {
            clearTimeout(checkPending)
            }
            let validatePass = (rule, value, callback) => {
            if (value === '') {
                callback(new Error('请输入密码'));
            } else {
                if (this.ruleForm.checkPass !== '') {
                this.$refs.ruleForm.validateField('checkPass');
                }
                callback();
            }
            }
            let validatePass2 = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请再次输入密码'));
                } else if (value !== this.ruleForm.pass) {
                    callback(new Error("两次密码不一致"));
                } else {
                    callback();
                }
            }
        return {
            procedure:'IDM_PUBLIC.IDM_GET_USERPWD',
            procedure1:'IDM_PUBLIC.IDM_GET_USERPERMISSON',
            procedureGet:'IDM_PUBLIC.IDM_UPD_USERPWD',
            url:{
                 list:'/crud/procedure',
                 procedure1:'/getPermission',
                getProcedure:'/crud/procedure'
            },
            Url:"https://www.baidu.com/",
            imgUrl:"http://10.37.1.49:18924/guorun-idm/sys/common/static/",
            visible: false,
            dataSource:[],
            // inargsList:[],
            // 提交密码
            getInargs:[],
            // avatr:[],
            // dataList:[],
            // password:[],
            ruleForm: {
                pass: '',
                checkPass: '',
            },
            rules: {
                pass: [{ validator: validatePass, trigger: 'change' }],
                checkPass: [{ validator: validatePass2, trigger: 'change' }],
            },
            layout: {
                labelCol: { span: 4 },
                wrapperCol: { span: 14 },
            },
        }
    },
    methods:{
        async showModal(item,index) {
            console.log("item",item)
            let inArgs = []
            let obj = {}
            obj['usercode'] = item.USERCODE
            obj['syscode'] = item.SYSCODE
            obj['deptcode'] = item.DEFAULTDEPTCODE
            inArgs.push(obj)
            const reqBody = {
                procedure:this.procedure,
                // 从用户权限(用于普通用户)返回的结果取值
                inArgs:inArgs,
                ifReturnCursor: true,
            }
            const res = await postAction(this.url.list,reqBody)
            if(res.code === 2000){
              this.getPassword = res.data.resultList[0]
              console.log("this.getPassword",this.getPassword)
            }
            const usercode = item.USERCODE
            const syscode = item.SYSCODE
            const idmuser = item.IDM_USERNAME
            const objects =  {usercode,syscode,idmuser}
            this.getInargs = objects
              if(!this.getPassword || this.getPassword === undefined){
                  this.visible = true
              }else{
                const empcode = item.USERCODE
                const deptcode = item.DEFAULTDEPTCODE
                const empcodeUrl = item.API.replace(/@usercode@/,empcode)
                const passwordUrl = empcodeUrl.replace(/@password@/,this.getPassword.CLEARTEXT)
                const deptcodeUrl = passwordUrl.replace(/@defaultdeptcode@/,deptcode)
                const compcodeUrl = deptcodeUrl.replace(/@compcode@/,"1")
                const ownercodeUrl = compcodeUrl.replace(/@ownercode@/,deptcode)
                console.log("ownercodeUrl",ownercodeUrl)
                var tempwindow = window.open('_blank')
                tempwindow.location = ownercodeUrl
              }
            },
        handleOk(e) {
            this.visible = false;
        },
        onSubmit(){},
        // 提交按钮
        submitForm(formName) {
            this.$refs[formName].validate(async valid => {
                if (valid) {
                    // 提交用户输入的密码
                    // 获取到的用户输入的密码
                    let cleartext = this.ruleForm.pass
                    // 把获取到的密码以键值对的形式加入对象里
                    this.getInargs['cleartext'] = cleartext
                    // 后台需要以数组的形式传入
                    let arrs = []
                    arrs.push(this.getInargs)
                    this.getInargs = arrs
                        const reqBody ={
                            procedure:this.procedureGet,
                            inArgs:this.getInargs,
                            ifReturnCursor: true
                        }
                  const res = await postAction(this.url.getProcedure,reqBody)
                    if(res.code ===2000){
                      // 提交完之后信息提示
                      this.$message.info('提交成功');
                      // 清除密码
                      this.$refs[formName].resetFields();
                      // 关闭模态框
                      this.visible = false;
                      this.getAuthority()
                    }
                } else {
                return false;
                }
            });
        },
        // 清空表单
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
        // 获取用户权限(用于普通用户)
        async getAuthority(){
          let usercode = store.getters.userInfo.username
          const reqBody ={ usercode: usercode,systype: "10" }
          const res = await postAction(this.url.procedure1,reqBody)
          if(res.code === 2000){
            this.dataSource = res.data.resultList
          }
        },
    },
    async created () {
       await this.getAuthority()
    },
}
</script>

<style lang="less" scoped>
p,ul,li{
    padding:0;
    margin:0;
    list-style:none
}
@media screen and(min-width: 1020px){
    .Idminternalsystem{
        height: 998px;
    }
}
@media screen and(max-width: 1020px){
    .Idminternalsystem{
        height: 100%;
    }
}
.Idminternalsystem{
    background-color: #ffffff;
    width: 100%;
    // height: 100%;
    .loginBox{
        margin: 0 auto;
    }
    .Idminternalsystem-text{
        font-size:30px;
        border-bottom: 1px solid #ddd;
        padding-left: 20px;
    }
    // .solid-line{
    // border: 1px solid #ddd;
    // margin: 0 20px 0 20px;
    // }
    .ul{
        padding-top: 10px;
        padding-left: 20px;
		.li{
			margin-top: 20px;
            padding-right: 50px;
			a {
                display: inline-block;
                width: 70%;
                border-bottom: 1px solid #ddd;
			    padding-bottom: 10px;
                overflow: hidden;
                img{
                width: 100%;
                height: 100px;
				border-radius: 10px;
			}
            }
			.text{
			    padding-right: 5px;
                margin-top: 10px;
                h5 {
                    font-size: 20px;
                }
			    p{
    		        display: inline;
                }
			}
		}
    }
}
</style>
